package csc309.datingapp;

import java.util.Date;
import java.util.Map;
import java.sql.*;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

public class RegisterUser extends ActionSupport implements SessionAware {

	private String email;
	private String confirmemail;
	private String password;
	private String confirmpassword;
	private String firstname;
	private String lastname;
	private String country;
	private String city;
	private String ethnicity;
	private String religion;
	private String politicalview;
	private int phonenumber;
	private String bbm;
	private int day;
	private int month;
	private int year;
	private int feet;
	private int inches;
	private String Gender;
	private String biography;
	private String interests;

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getConfirmemail() {
		return confirmemail;
	}

	public void setConfirmemail(String confirmemail) {
		this.confirmemail = confirmemail;
	}

	public String getConfirmpassword() {
		return confirmpassword;
	}

	public void setConfirmpassword(String confirmpassword) {
		this.confirmpassword = confirmpassword;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getEthnicity() {
		return ethnicity;
	}

	public void setEthnicity(String ethnicity) {
		this.ethnicity = ethnicity;
	}

	public String getReligion() {
		return religion;
	}

	public void setReligion(String religion) {
		this.religion = religion;
	}

	public String getPoliticalview() {
		return politicalview;
	}

	public void setPoliticalview(String politicalview) {
		this.politicalview = politicalview;
	}

	public int getPhonenumber() {
		return phonenumber;
	}

	public void setPhonenumber(int phonenumber) {
		this.phonenumber = phonenumber;
	}

	public String getBbm() {
		return bbm;
	}

	public void setBbm(String bbm) {
		this.bbm = bbm;
	}

	public int getFeet() {
		return feet;
	}

	public void setFeet(int feet) {
		this.feet = feet;
	}

	public int getInches() {
		return inches;
	}

	public void setInches(int inches) {
		this.inches = inches;
	}

	public String getGender() {
		return Gender;
	}

	public void setGender(String gender) {
		Gender = gender;
	}

	public String getBiography() {
		return biography;
	}

	public void setBiography(String biography) {
		this.biography = biography;
	}

	public String getInterests() {
		return interests;
	}

	public void setInterests(String interests) {
		this.interests = interests;
	}

	public int getDay() {
		return day;
	}

	public void setDay(int day) {
		this.day = day;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public String errormsg;

	public String getErrormsg() {
		return errormsg;
	}

	public void setErrormsg(String error) {
		this.errormsg = error;
	}

	public String execute() {

		Connection con;
		try {
			String dbUsername = "group09";
			String dbPassword = "asdasdqr3ggqq";

			
			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager.getConnection(
					"jdbc:mysql://bungle07.cs.toronto.edu", dbUsername,
					dbPassword);

			Statement sql = con.createStatement();

			// String query="select * from students";
			// ResultSet rs = stmt.executeQuery(query);

			sql.executeUpdate("INSERT INTO group09.users VALUES ('"
					+ getEmail() + "', '" + getFirstname() + "', '"
					+ getLastname() + "', '" + getPassword() + "', '/pics/babak.jpg', '"
					+ getBbm() + "')");

			String dob = getYear() + "-" + getMonth() + "-" + getDay();
			sql.executeUpdate("INSERT INTO group09.details VALUES ('"
					+ getEmail() + "', '" + getGender() + "', '" + dob + "', '"
					+ getCountry() + "', '" + getCity() + "', '" + getFeet()
					+ "ft" + getInches() + "', '" + getEthnicity() + "', '"
					+ getReligion() + "', '" + getPoliticalview() + "', '"
					+ getBiography() + "', '" + getInterests() + "', '"
					+ getPhonenumber() + "')");

			sql.close();
			con.close();
			return "success";
		} catch (Exception e) {
			setErrormsg(e.getMessage());
			return "exception";
		}
		//return "exception";
	}

	/* JavaBeans Properties to Receive Request Parameters */

	private Map session;

	public void setSession(Map session) {
		this.session = session;

	}
}
